//bf
#include<iostream>
#include<string>

using namespace std;
//bf algorithm
int b_f(string t,string s) 
{
	for(int i=0;i <= t.length() - s.length();i++){
	int flag = true;
	for(int j = 0; s[j] != '\0'; j++)
	{
		if(t[i + j] != s[j]) 
		{
		   flag = false;
		   break;
		} 						
	}
	if(flag) return i;
	}
	return -1;
}
//kmp  get the next array
void getNext(int* next, const string& s) {
    int j = 0;
    next[0] = 0;
    for(int i = 1; i < s.size(); i++) 
	{
        while (j > 0 && s[i] != s[j]) j = next[j - 1];
        if (s[i] == s[j]) j++;
        
        next[i] = j;
    }
}
//kmp
int kmp(string haystack, string needle) {
    if (needle.size() == 0) return 0;
    int next[needle.size()];
    getNext(next, needle);
    int j = 0;
    for (int i = 0; i < haystack.size(); i++) 
	{
        while(j > 0 && haystack[i] != needle[j]) j = next[j - 1];
        
        if (haystack[i] == needle[j]) j++;
        
        if (j == needle.size() ) return (i - needle.size() + 1);
    }
    return -1;
    }
int main()
{

string t,s;
	cin >> t >> s;
	int a[s.length()];
	cout<<kmp(t,s);
	return 0;
}
